import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const commonRoutes = [
    {
        path: '/login',
        name: 'login',
        meta: { title: '登录' },
        component: () => import('../components/Login.vue'),
    },
     {
        path: '/reg',
        name: 'reg',
        meta: { title: '注册' },
        component: () => import('../components/Reg.vue'),
    },
    {
        path: '/404',
        name: '404',
        meta: { title: '404' },
        component: () => import('../components/404.vue'),
    },
    { path: '/', redirect: '/data' },
]

// 本地所有的页面 需要配合后台返回的数据生成页面
export const asyncRoutes = {
    data: {
        path: 'data',
        name: 'data',
        meta: { title: '数据概览' },
        component: () => import('../views/Data.vue'),
    },
    rentArea: {
        path: 'rentArea',
        name: 'rentArea',
        meta: { title: '面积租金散点图' },
        component: () => import('../views/RentArea.vue'),
    },
    houseTag: {
        path: 'houseTag',
        name: 'houseTag',
        meta: { title: '标签词云' },
        component: () => import('../views/HouseTag.vue'),
    },
    houseRent: {
        path: 'houseRent',
        name: 'houseRent',
        meta: { title: '租金分析' },
        component: () => import('../views/HouseRent.vue'),
    },
    houseNum: {
        path: 'houseNum',
        name: 'houseNum',
        meta: { title: '房源数量' },
        component: () => import('../views/HouseNum.vue'),
    },
    houseRentAvg: {
        path: 'houseRentAvg',
        name: 'houseRentAvg',
        meta: { title: '平均房租' },
        component: () => import('../views/HouseRentAvg.vue'),
    },
    yuce: {
        path: 'yuce',
        name: 'yuce',
        meta: { title: '租金预测' },
        component: () => import('../views/HouseRentYC.vue'),
    },
    password: {
        path: 'password',
        name: 'password',
        meta: { title: '修改密码' },
        component: () => import('../views/Password.vue'),
    },
    getdata: {
        path: 'getdata',
        name: 'getdata',
        meta: { title: '获取数据' },
        component: () => import('../views/GetData.vue'),
    },
    userinfo: {
        path: 'userinfo',
        name: 'userinfo',
        meta: { title: '用户信息' },
        component: () => import('../views/UserInfo.vue'),
    },
    datalog: {
        path: 'datalog',
        name: 'datalog',
        meta: { title: '爬取日志' },
        component: () => import('../views/Datalog.vue'),
    },
}

const createRouter = () => new Router({
    routes: commonRoutes,
})

const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

export default router
